<?php

namespace Fuel\Migrations;

class Create_orders
{
	public function up()
	{
		\DBUtil::create_table('orders', array(
			'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
			'show_id' => array('constraint' => 11, 'type' => 'int'),
			'user_id' => array('constraint' => 11, 'type' => 'int'),
                        'first_name' => array('constraint' => 30, 'type' => 'varchar'),
                        'last_name' => array('constraint' => 30, 'type' => 'varchar'),
                        'email' => array('constraint' => 255, 'type' => 'varchar'),
                        'phone_nr' => array('constraint' => 25, 'type' => 'varchar'),
			'is_paid' => array('type' => 'tinyint'),
			'purchase_time' => array('constraint' => 11, 'type' => 'int')

		), array('id'));
                
                $all_orders = array(
                    array('show_id' => 1, 'user_id' => 2, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@mail.com', 'phone_nr' => '12345678', 'is_paid' => 1, 'purchase_time' => 1401708600),
                    array('show_id' => 2, 'user_id' => 2, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@mail.com', 'phone_nr' => '12345678', 'is_paid' => 0, 'purchase_time' => 1401708600),
                    array('show_id' => 3, 'user_id' => 2, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@mail.com', 'phone_nr' => '12345678', 'is_paid' => 0, 'purchase_time' => 1401708600),
                    array('show_id' => 4, 'user_id' => 3, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@mail.com', 'phone_nr' => '12345678', 'is_paid' => 1, 'purchase_time' => 1401708600),
                    array('show_id' => 5, 'user_id' => 3, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@mail.com', 'phone_nr' => '12345678', 'is_paid' => 0, 'purchase_time' => 1401708600),
                    array('show_id' => 6, 'user_id' => 3, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@mail.com', 'phone_nr' => '12345678', 'is_paid' => 1, 'purchase_time' => 1401708600),
                    array('show_id' => 7, 'user_id' => 2, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@mail.com', 'phone_nr' => '12345678', 'is_paid' => 0, 'purchase_time' => 1401708600),
                    array('show_id' => 8, 'user_id' => 3, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => 'john.doe@mail.com', 'phone_nr' => '12345678', 'is_paid' => 1, 'purchase_time' => 1401708600)
                );
                
                foreach($all_orders as $data) {
                    $order = \Model_Orm_Order::forge();
                    $order->show_id = $data['show_id'];
                    $order->user_id = $data['user_id'];
                    $order->first_name = $data['first_name'];
                    $order->last_name = $data['last_name'];
                    $order->email = $data['email'];
                    $order->phone_nr = $data['phone_nr'];
                    $order->is_paid = $data['is_paid'];
                    $order->purchase_time = $data['purchase_time'];
                    $order->save();
                }
	}

	public function down()
	{
		\DBUtil::drop_table('orders');
	}
}